package ui;

import IOexpand.IOExpand;
import Offline.Offline;
import TEC.Tec;
import interrupt.GUI;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.embed.swing.SwingNode;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

import javax.swing.*;
import java.io.IOException;

public class Ui extends Application {

    private IOExpand ioExpand;
    private BorderPane borderPane;
    private Offline offline;
    private GUI interrupt;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage myStage) throws IOException {

        borderPane = new BorderPane();
        MenuBar menuBar = new MenuBar();

        Label label = new Label("Offline!");
        label.setOnMouseClicked(mouseEvent->{getOffline();});
        Menu menuOffline = new Menu("", label);


        label = new Label("Interrupt");
        label.setOnMouseClicked(mouseEvent->{getInterrupt();});
        Menu menuInterrupt = new Menu("",label);


        label = new Label("IOExpend!");
        label.setOnMouseClicked(mouseEvent->{try {
            getIOExpand();
        } catch (IOException e) {
            e.printStackTrace();
        }});
        Menu menuIOExpend = new Menu("",label);

        menuBar.getMenus().addAll(menuOffline,menuInterrupt,menuIOExpend);
        borderPane.setTop(menuBar);


        myStage.setTitle("机组集成实验模拟器");
        myStage.setResizable(false);
        Scene scene = new Scene(borderPane,1205,725);

        myStage.setScene(scene);
        getOffline();
        myStage.show();

    }

    private void getIOExpand() throws IOException{
        if (ioExpand==null){
            ioExpand = new IOExpand();
        }
        Parent root = ioExpand.getIOExpand();
        borderPane.setCenter(root);
    }

    private void getOffline(){
        if (offline==null){
            offline = new Offline();
        }

        final SwingNode swingNode = new SwingNode();
        swingNode.setContent(offline.getOffline());
        borderPane.setCenter(swingNode);


    }

    private void getInterrupt(){
        if (interrupt == null){
            interrupt = new GUI();
        }

        final  SwingNode swingNode = new SwingNode();
        swingNode.setContent(interrupt.getjPanel());
        borderPane.setCenter(swingNode);
    }
}
